﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExitGames.Logging;
using PhotonServerCommon.Enums;
using PhotonServerFramework.Implementation.Handler;
using PhotonServerFramework.Interfaces.Client;
using PhotonServerFramework.Interfaces.Telegram;

namespace MasterServer.Handler.Request
{
    public class RealmTransferRequestHandler : ClientTelegramHandler
    {
        /// <summary>
        /// Logger instance
        /// </summary>
        public override ILogger Logger { get; }

        /// <summary>
        /// Unique handler id
        /// </summary>
        public override Guid HandlerId { get; set; } = Guid.NewGuid();

        /// <summary>
        /// Handler type (Request, Response or Event)
        /// </summary>
        public override HandlerTypes HandlerType => HandlerTypes.Request;

        /// <summary>
        /// OperationCode that the handler can handle
        /// </summary>
        public override byte HandlerCode => (byte) OperationCodes.Transfer;

        /// <summary>
        /// OperationSubCode that the handler can handle
        /// </summary>
        public override int HandlerSubCode => (int) OperationSubCodes.RealmTransfer;

        public RealmTransferRequestHandler(ILogger logger)
        {
            Logger = logger;
        }

        /// <summary>
        /// Tries to handle the incoming telegram from the given TPeer (normally IClientPeer)
        /// </summary>
        /// <param name="telegram">The telegram to be handled</param><param name="clientPeer">The peer requesting the handling</param>
        /// <returns>
        /// true if handled, otherwise false
        /// </returns>
        public override bool HandleTelegram(ITelegram telegram, IClientPeer clientPeer)
        {
            bool handled = false;

            Logger.InfoFormat("Trying to handle telegram of type={0} with code={1}, subcode={2}", telegram.Type,
                (OperationCodes)telegram.TelegramCode, (OperationSubCodes)telegram.TelegramSubCode);

            return handled;
        }
    }
}
